import { reqGetSearchInfo } from "@/api"

//search模块的小仓库
const state = {
    searchInfo: {}
}

const actions = {
    //params参数：是当用户派发action的时候，第二个参数传递进来的，至少是一个空对象
    async getSearchInfo({commit}, params={}){
        let result = await reqGetSearchInfo(params)
        if(result.code == 200){
            commit('GETSEARCHINFO', result.data)

        }
    }
}

const mutations = {
    GETSEARCHINFO(state, searchInfo){
        state.searchInfo = searchInfo
    }
}

//简化仓库中的数据
const getters = {
    goodsList(state){
        //这里的state是当前仓库state
        return state.searchInfo.goodsList || []
    },
    trademarkList(state){
        return state.searchInfo.trademarkList || []
    },
    attrsList(state){
        return state.searchInfo.attrsList || []
    },
    total(state){
        return state.searchInfo.total || 0
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}